// Copyright (c) Omar AL Zabir. All rights reserved.
// For continued development and updates, visit http://msmvps.com/omar

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;


using System.Data.Linq;
using System.Linq;

using Dropthings.DataAccess;

namespace Dropthings.Business.Activities
{
    public partial class AddWidgetZoneActivity : System.Workflow.ComponentModel.Activity
	{
        public AddWidgetZoneActivity()
		{
			InitializeComponent();
		}

        private static DependencyProperty WidgetZoneTitleProperty = DependencyProperty.Register("WidgetZoneTitle", typeof(string), typeof(AddWidgetZoneActivity));

        public string WidgetZoneTitle
        {
            get { return (string)base.GetValue(WidgetZoneTitleProperty); }
            set { base.SetValue(WidgetZoneTitleProperty, value); }
        }

        private static DependencyProperty NewWidgetZoneProperty = DependencyProperty.Register("NewWidgetZone", typeof(WidgetZone), typeof(AddWidgetZoneActivity));

        [ValidationOptionAttribute(ValidationOption.Required)]
        [Browsable(true)]
        public WidgetZone NewWidgetZone
        {
            get { return (WidgetZone)base.GetValue(NewWidgetZoneProperty); }
            set { base.SetValue(NewWidgetZoneProperty, value); }
        }


        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
           this.NewWidgetZone = DatabaseHelper.Insert<WidgetZone>(DatabaseHelper.SubsystemEnum.WidgetInstance,
                  (newWidgetZone) =>
                  {
                      string title = this.WidgetZoneTitle;
                      ObjectBuilder.BuildDefaultWidgetZone(newWidgetZone, title, title, 0);
                  });

            return ActivityExecutionStatus.Closed;
        }
	}
}
